﻿<?php include $this->admin_tpl('meta');?>
<title>商品列表</title>
<script type="text/javascript" src="<?php echo STATIC_URL;?>plugin/jquery/1.8.2/jquery.min.js"></script>
</head>
<body>
<div class="page-container" style="padding-bottom:0;">
	<form id="search">
		<input type="hidden" value="" name="field">
		<input type="hidden" value="" name="order">
		<input type="hidden" value="0" name="download">
		<div class="c hidden-xs" style="display:inline-block"><input type="text" name="i_id" class="input-text search" autocomplete="off" placeholder="款式编码,*号开头模糊匹配" value=""></div>
		<div class="c"><input type="text" name="sku_id" class="input-text search" autocomplete="off" placeholder="商品编码,*号开头模糊匹配" value=""></div>
		<div class="c hidden-xs"><input type="text" name="sku_code" class="input-text search" autocomplete="off" placeholder="国标码" value=""></div>
		<div class="c"><input type="text" name="name" class="input-text search" autocomplete="off" placeholder="商品名称" value=""></div>
		<div class="c hidden-xs"><input type="text" name="properties_value" class="input-text search hidden-xs" autocomplete="off" placeholder="颜色尺码" value=""></div>
		<div class="c hidden-xs"><input type="text" name="other_2" class="input-text search" autocomplete="off" placeholder="其他属性2" value=""></div>
		<div class="select-box inline c hidden-xs">
			<select name="enabled" class="select">
				<option value="">是否启用</option>
				<option value="1">启用</option>
				<option value="0">备用</option>
				<option value="-1">禁用</option>
			</select>
		</div>
		<?php include $this->admin_tpl('jst_common/select_brand');?>
		<?php include $this->admin_tpl('jst_common/select_category');?>
		<div class="select-box inline c hidden-xs">
			<select name="is_syn" class="select">
				<option value=""  selected>数据处理</option>
				<option value="1">已同步库存</option>
				<option value="2">未同步库存</option>
				<option value="3">未更新资料</option>
				<option value="4">已更新资料</option>
			</select>
		</div>
		<a class="btn btn-success radius" href="javascript:void(0)" id="btn_search"><i class="yzm-iconfont yzm-iconsousuo"></i> 搜索</a>
		<button class="btn btn-primary radius" id="btn_reset" type="reset"><i class="yzm-iconfont yzm-iconshuaxin"></i> 重置</button>
		<button name="dosubmit" class="btn btn-warning radius hidden-xs" type="button" id="btn_download" url="<?php echo U('sku_list');?>"><i class="yzm-iconfont yzm-iconxiazai"> 导出</i></button>
	</form>
	
	<table id="table" class="mt-20" lay-filter="table" style="font-size:12px;"></table>
</div>
<script type="text/html" id="tool_temp">
	<a href="javascript:;" class="btn btn_action btn-primary radius" action_url="<?php echo U('reget_sku')?>"><i class="yzm-iconfont yzm-iconshuaxin"></i> 重新获取商品</a>
	<a href="javascript:;" class="btn btn_action btn-primary radius" action_url="<?php echo U('reget_inventory')?>"><i class="yzm-iconfont yzm-iconshuaxin"></i> 重新拉取库存</a>
	<a href="javascript:;" id="btn_del" class="btn btn-danger radius"><i class="yzm-iconfont yzm-iconshanchu2"></i> 批量删除</a>
</script>
<?php include $this->admin_tpl('jst_common/common_tpl');?>
<?php include $this->admin_tpl('footer');?>
<script type="text/javascript" src="<?php echo STATIC_URL;?>plugin/layui/layui.js"></script>
<script>
var db = 'jst_sku';
layui.use(function(){ //亦可加载特定模块：layui.use(['layer', 'laydate', function(){
	table = layui.table; //表格
	util = layui.util; //工具集
	dropdown = layui.dropdown; //下拉菜单
	form = layui.form;
	//var index = layer.load(1);
	//执行一个 table 实例
	option = {
		elem: '#table',
		id:'table',
		height: 'full-80',
		limit:30,
		limits:[30,60,90],
		url:'<?php echo U('sku_list');?>',
		method:'post',
		where: $('#search').serializeJson(),
		title: '商品列表',
		autoSort: false,
		totalRow: true, // 开启合计行
		page: {theme:'#409eff',groups:3,hash:true}, //开启分页
		toolbar: '#tool_temp', //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
		cols: [[ //表头
			{type: 'checkbox',width:40},
			{field: 'id', title: 'ID', width:80,align:'center'},
			{field: 'pic', title: '图片', width:40,align:'center',templet:'#pic_tpl'},
			{field: 'i_id', title: '款式编码', width:100,align:'left',templet:'#vip_link'},
			{field: 'sku_id', title: '商品编码', width:150,align:'left'},
			{field: 'sku_code', title: '国标码',align:'left'},
			{field: 'other_2', title: '其他属性2',align:'left',width:150},
			{field: 'properties_value', title: '商品属性',align:'left',width:120},
			{field: 'name', title: '商品名称',align:'left',width:150},
			{field: 'labels', title: '商品标签',align:'left',width:200,templet:function(row){
				html = '';
				if(row.labels_brand){
					labels_brand = row.labels_brand;
					labels_brand = labels_brand.replace('-', '').replace('+','');
					switch (labels_brand) {
						case '爆款':
							class_name = 'label-danger';
							break;
						case '畅销':
							class_name = 'label-warning';
							break;
						case '平销':
							class_name = 'label-secondary';
							break;
						case '小销量':
							class_name = 'label-primary';
							break;
						case '滞销':
							class_name = 'label-default';
							break;
						case '零销':
							class_name = 'label-default';
							break;
						default:
							class_name = 'label-default';
					}
					html += '<span class="label '+class_name+' radius">'+row.labels_brand+'</span>';
					if(row.labels){
						labels = row.labels.split(',');
						$.each(labels,function(index, value) {
							html +=' <span class="label label-success radius">'+value+'</span>';
						});
					}
				}
				return html;
			}},
			{field: 'category', title: '分类',align:'center',width:120},
			{field: 'brand', title: '品牌',align:'center',width:80},
			{field: 'enabled', title: '状态',align:'center',width:50,templet:function(row){
				if(row.enabled == 1){
					return '<span class="yzm-status-enable"><i class="yzm-iconfont">&#xe81f;</i>启用</span>';
				}else if(row.enabled == 0){
					return '<i class="yzm-iconfont">&#xe601;</i>备用';
				}else{
					return '<span class="yzm-status-disable"><i class="yzm-iconfont">&#xe601;</i>禁用</span>';
				}
			}},
			{field: 'supplier_name', title: '供应商',align:'center',width:80,totalRow: '小计：'},
			{field: 'qty', title: '库存',align:'center',width:50,sort:true,totalRow:true,totalRowDecimals:0},
			{field: 'cost_price', title: '成本价',align:'center',width:50,sort:true},
			{field: '1days', title: '昨天',align:'center',width:50,sort:true,totalRow:true,totalRowDecimals:0},
			{field: '2days', title: '2天',align:'center',width:50,sort:true,totalRow:true,totalRowDecimals:0},
			{field: '3days', title: '3天',align:'center',width:50,sort:true,totalRow:true,totalRowDecimals:0},
			{field: '7days', title: '7天',align:'center',width:50,sort:true,totalRow:true,totalRowDecimals:0},
			{field: '30days', title: '30天',align:'center',width:50,sort:true,totalRow:true,totalRowDecimals:0},
			{field: 'add_time', title: '抓取时间',align:'center',width:80,sort:true,templet: function(row) {
					if(row.add_time){return util.toDateString(row.add_time*1000, 'MM-dd HH:mm');}else{
						return '-';
					}
				}
			},
			{field: 'inventory_syn_time', title: '库存同步',align:'center',width:80,sort:true,templet: function(row) {
					if(row.inventory_syn_time){return util.toDateString(row.inventory_syn_time*1000, 'MM-dd HH:mm');}else{
						return '-';
					}
				}
			},
			{field: 'modified', title: '修改时间',align:'center',width:110,sort:true,templet: function(row) {return util.toDateString(row.modified*1000, 'yy-MM-dd HH:mm:ss');}},
			{field: 'jst_name', title: '商品来源',align:'center',width:60},
			{field: 'jst_name2', title: '库存来源',align:'center',width:60},
		]],
		done:function(res,curr,count){
			var options = this;
			//layer.close(index);
			public_table(db);
			select_table(options,<?php echo json_encode($this->jst_arr);?>,'.dropdown-jst',db,'jst_id');
		}
	};
	table.render(option);
	table.hideCol('table', {
	  field: 'id', // 对应表头的 field 属性值
	  hide: true // `true` or `false`
	});
	table.hideCol('table', {
	  field: 'sku_code', // 对应表头的 field 属性值
	  hide: true // `true` or `false`
	});
	init_table(db);
})
	
</script>
</body>
</html>